package org.itworks.biodev.model;

import java.sql.*;
import java.util.*;

public class ProductTypeSpecificityTable extends AbstractTable<ProductTypeSpecificity> {

	private static ProductTypeSpecificityTable productTypeSpecificityTable = null;
	
	@Override
	public boolean add(ProductTypeSpecificity object) {
		return false;
	}

	@Override
	public boolean delete(ProductTypeSpecificity object) {
		return false;
	}

	@Override
	public boolean update(ProductTypeSpecificity object) {
		// TODO Auto-generated method stub
		return false;
	}
	
	public Vector<ProductTypeSpecificity> findAll() throws Exception {
		return getMultipleResults("SELECT * FROM product_type_specificity");
	}
	
	private Vector<ProductTypeSpecificity> getMultipleResults(String sqlQuery) throws Exception {
		Vector<ProductTypeSpecificity> productTypeSpecificities = new Vector<ProductTypeSpecificity>();
		
		Statement statement = BiodevDatabase.getConnection().createStatement();
		ResultSet resultSet = statement.executeQuery(sqlQuery);
		
		while(resultSet.next()) {
			ProductTypeSpecificity productTypeSpecificity = new ProductTypeSpecificity();
			productTypeSpecificity.setId(Integer.parseInt(resultSet.getObject("id").toString()));
			productTypeSpecificity.setLabel(resultSet.getObject("label").toString());
			productTypeSpecificity.setProductCategoryId(Integer.parseInt(resultSet.getObject("product_category_id").toString()));
			
			productTypeSpecificities.add(productTypeSpecificity);
		}
		
		return productTypeSpecificities;
	}
	
	public Vector<ProductTypeSpecificity> findAllByProductCategoryId(int id) throws Exception {
		return getMultipleResults("SELECT * FROM product_type_specificity WHERE product_category_id = " + id);
	}
	
	public static ProductTypeSpecificityTable getInstance() {
		if(productTypeSpecificityTable == null) {
			productTypeSpecificityTable = new ProductTypeSpecificityTable();
		}
		return productTypeSpecificityTable;
	}

}
